<?php 
include 'Mail.php';
include 'Mail/mime.php' ;


$email_address = $_POST["email_address"];

if ($email_address == '' or $email_address == null) {
	$email_address = $_GET["email_address"];
}

$type = $_POST["type"];

if ($type == '' or $type == null) {
	$type = $_GET["type"];
}

$email_address = "ncastro@xeliom.com";

$username = 'ncastro@xeliom.com';
$password = 'nico.287';
$host = 'mail.xeliom.com';

$fileName = '/planillas/apartamento.xlsx';

$text = 'Text version of email';
$html = '<html><body>HTML version of email</body></html>';
$file = $fileName;
$crlf = "\n";
$hdrs = array(
		'From'    => $username,
		'Subject' => 'Test mime message'
);

$mime = new Mail_mime(array('eol' => $crlf));

$mime->setTXTBody($text);
$mime->setHTMLBody($html);
$mime->addAttachment($file, 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');

$body = $mime->get();
$hdrs = $mime->headers($hdrs);

$mail =& Mail::factory( 'smtp', array('host' => $host,
          'auth' => true,
          'port' => 25,
          'username' => $username,
          'password' => $password ) );

try{
	$result = $mail->send($email_address, $hdrs, $body);
	if ( PEAR::isError($result) ) {
		$result = $result->getMessage();
		$status = 'ok';
	} else {
		$result = "Message successfully sent";
		$status = 'ok';
	}
}catch(Exception $e){
	$status = 'error';
	$result =  $e;
}


$data = array('status' => $status, 'email' => $email_address, 'message' => $result);

$json = json_encode($data);

echo $json;
?>